package com.tancire.member.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tancire.common.annotation.Log;
import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.enums.BusinessType;
import com.tancire.member.domain.MemberTrainChart;
import com.tancire.member.service.IMemberTrainChartService;
import com.tancire.common.utils.poi.ExcelUtil;
import com.tancire.common.core.page.TableDataInfo;

/**
 * 会员排行榜Controller
 *
 * @author tancire
 * @date 2024-10-23
 */
@RestController
@RequestMapping("/member/memberTrainChart")
public class MemberTrainChartController extends BaseController {

    @Resource
    private IMemberTrainChartService memberTrainChartService;

    /**
     * 查询会员排行榜列表
     */
    @PreAuthorize("@ss.hasPermi('member:memberTrainChart:list')")
    @GetMapping("/list")
    public TableDataInfo list(MemberTrainChart memberTrainChart) {
        startPage();
        List<MemberTrainChart> list = memberTrainChartService.selectMemberTrainChartList(memberTrainChart);
        return getDataTable(list);
    }

    /**
     * 导出会员排行榜列表
     */
    @PreAuthorize("@ss.hasPermi('member:memberTrainChart:export')")
    @Log(title = "会员排行榜", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MemberTrainChart memberTrainChart) {
        List<MemberTrainChart> list = memberTrainChartService.selectMemberTrainChartList(memberTrainChart);
        ExcelUtil<MemberTrainChart> util = new ExcelUtil<MemberTrainChart>(MemberTrainChart.class);
        util.exportExcel(response, list, "会员排行榜数据");
    }

    /**
     * 获取会员排行榜详细信息
     */
    @PreAuthorize("@ss.hasPermi('member:memberTrainChart:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(memberTrainChartService.selectMemberTrainChartById(id));
    }

    /**
     * 新增会员排行榜
     */
    @PreAuthorize("@ss.hasPermi('member:memberTrainChart:add')")
    @Log(title = "会员排行榜", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MemberTrainChart memberTrainChart) {
        return toAjax(memberTrainChartService.insertMemberTrainChart(memberTrainChart));
    }

    /**
     * 修改会员排行榜
     */
    @PreAuthorize("@ss.hasPermi('member:memberTrainChart:edit')")
    @Log(title = "会员排行榜", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MemberTrainChart memberTrainChart) {
        return toAjax(memberTrainChartService.updateMemberTrainChart(memberTrainChart));
    }

    /**
     * 删除会员排行榜
     */
    @PreAuthorize("@ss.hasPermi('member:memberTrainChart:remove')")
    @Log(title = "会员排行榜", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(memberTrainChartService.deleteMemberTrainChartByIds(ids));
    }

    /**
     * 刷新排行榜信息
     */
    @PreAuthorize("@ss.hasPermi('member:memberTrainChart:refresh')")
    @GetMapping("/refresh/chart")
    public AjaxResult refreshChart() {
        memberTrainChartService.refreshChart();
        return AjaxResult.success();
    }
}
